﻿using System.ComponentModel;

namespace Riba.MVVMSL
{
	///<summary>
	///<para>Enumeration for different animation modes.</para>
	///</summary>
	///<remarks>
	///<para>Even if your custom animation has nothing to do with a change of direction, you can use this Enumeration to distinguish different visual states.</para>
	///<para>Refer to http://www.SilverlightBlog.Net for a tutorial on how to create custom animations for the NavigatorControl.</para>
	///</remarks>
	[TypeConverter(typeof(AnimationModeConverter))]
	public enum AnimationMode
	{
		///<summary>
		///<para>No animation will be applied</para>
		///</summary>
		None,
		///<summary>
		///<para>Proceeds the storyboard in forward direction</para>
		///</summary>
		Forward,
		///<summary>
		///<para>Proceeds the storyboard in backward direction</para>
		///</summary>
		Backward
	}

	internal class AnimationModeConverter : TypeConverter
	{
		public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType)
		{
			return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
		}

		public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
		{
			var modeString = value as string;

			switch (modeString)
			{
				case "Forward":
					return AnimationMode.Forward;
				case "Backward":
					return AnimationMode.Backward;
				default:
					return AnimationMode.None;
			}
		}
	}
}